 const express = require('express');
const mysql = require('mysql2');
const cors = require('cors');
const app = express();
const port = 3000;

app.use(cors());

// 创建数据库连接
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '254243zxx00', // 
  database: 'mydatabase'
});

// 处理获取数据的请求
app.get('/items', (req, res) => {
  //name,category,sales,sales_2 
  connection.query('SELECT * FROM items', (error, results) => {
    if (error) throw error;
    res.json(results);
  });
});

// 启动服务器
app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});
